class Vector3D:
    def __init__(self, x=0, y=0, z=0):
        """初始化三维向量的x、y、z分量"""
        self.x = x
        self.y = y
        self.z = z

    def __add__(self, scalar):
        """向量与标量相加：每个分量分别加标量"""
        if not isinstance(scalar, (int, float)):
            raise TypeError("只能与数字类型的标量进行加法运算")
        return Vector3D(self.x + scalar, self.y + scalar, self.z + scalar)

    def __sub__(self, scalar):
        """向量与标量相减：每个分量分别减标量"""
        if not isinstance(scalar, (int, float)):
            raise TypeError("只能与数字类型的标量进行减法运算")
        return Vector3D(self.x - scalar, self.y - scalar, self.z - scalar)

    def __mul__(self, scalar):
        """向量与标量相乘：每个分量分别乘标量"""
        if not isinstance(scalar, (int, float)):
            raise TypeError("只能与数字类型的标量进行乘法运算")
        return Vector3D(self.x * scalar, self.y * scalar, self.z * scalar)

    def __truediv__(self, scalar):
        """向量与标量相除：每个分量分别除以标量（标量不能为0）"""
        if not isinstance(scalar, (int, float)):
            raise TypeError("只能与数字类型的标量进行除法运算")
        if scalar == 0:
            raise ZeroDivisionError("除数不能为0")
        return Vector3D(self.x / scalar, self.y / scalar, self.z / scalar)

    def __repr__(self):
        """返回向量的字符串表示，方便打印"""
        return f"Vector3D({self.x}, {self.y}, {self.z})"


# 测试示例
if __name__ == "__main__":
    v = Vector3D(1, 2, 3)
    print("原向量：", v)  # 输出：Vector3D(1, 2, 3)

    # 向量加标量
    v_add = v + 2
    print("加2后：", v_add)  # 输出：Vector3D(3, 4, 5)

    # 向量减标量
    v_sub = v - 1
    print("减1后：", v_sub)  # 输出：Vector3D(0, 1, 2)

    # 向量乘标量
    v_mul = v * 3
    print("乘3后：", v_mul)  # 输出：Vector3D(3, 6, 9)

    # 向量除标量
    v_div = v / 2
    print("除以2后：", v_div)  # 输出：Vector3D(0.5, 1.0, 1.5)